package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.api.domain.vo.SysAuditHistoryVo;
import com.sale.system.domain.SysExamine;
import com.sale.system.domain.dto.SysAuditHistoryDto;
import com.sale.system.service.ISysExamineService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Description 审核控制层
 * @Param
 * @Date 22-12-08
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/examine")
public class SysExamineController extends BaseController {

    private final ISysExamineService sysExamineService;

    /**
     * 获取审核配置
     */
    //@SaCheckPermission("system:examine:list")
    @GetMapping("/list")
    public TableDataInfo<SysExamine> list(SysExamine SysExamine, PageQuery pageQuery)
    {
        return sysExamineService.selectExamineList(SysExamine,pageQuery);
    }

    /**
     * 新增审核信息
     */
    //@SaCheckPermission("system:examine:add")
    @Log(title = "审核信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysExamine SysExamine) throws Exception {
        return toAjax(sysExamineService.insertExamine(SysExamine));
    }

    /**
     * 删除审核信息
     */
    //@SaCheckPermission("system:examine:remove")
    @Log(title = "审核信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{examineId}")
    public R<Void> remove(@PathVariable("examineId") String examineId) throws Exception {
        return toAjax(sysExamineService.deleteExamine(examineId));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("system:examine:query")
    @GetMapping(value = "/{examineId}")
    public R<Map<String, Object>> getAppInfo(@PathVariable long examineId)
    {
        Map<String, Object> ajax = new HashMap<>();
        ajax.put("sysExamine",sysExamineService.getExamineInfo(examineId));
        return R.ok(ajax);
    }

    /**
     * 修改审核信息
     */
    //@SaCheckPermission("system:examine:edit")
    @Log(title = "审核配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody SysExamine sysExamine) throws Exception {
        return toAjax(sysExamineService.updateSysExamineEdit(sysExamine));
    }


    /**
     * 根据权限码进行审核
     */
    @GetMapping(value = "/sequence")
    public R<Void> getSequence(SysAuditHistoryVo sysAuditHistoryVo) throws Exception
    {
        return toAjax(sysExamineService.getSequence(sysAuditHistoryVo));
    }

    /**
     * 根据权限码获取审核历史
     */
    @GetMapping(value = "/history")
    public R<List<SysAuditHistoryDto>> getAuditHistory(SysAuditHistoryVo sysAuditHistoryVo)
    {
        List<SysAuditHistoryDto> list = sysExamineService.getAuditHistory(sysAuditHistoryVo);
        return R.ok(list);
    }

    /**
     * 修改审核类型
     */
    @PutMapping("/editHistory")
    public R<Void> editHistory(@RequestBody SysAuditHistoryVo sysAuditHistoryVo) {
        return toAjax(sysExamineService.updateHistoryAppConfigEdit(sysAuditHistoryVo));
    }


}
